#include "OLED_Task.h"
#include "freertos/queue.h"


EventGroupHandle_t Oled_EventGroupHandle =  NULL;

void OLED_task(void*p)
{
    EventBits_t Event_flag = 0xff;
    u8*show_str = NULL;
    u8 show_Time[64];
    static u32 show_num;
    while (1)
    {
        Event_flag = xEventGroupWaitBits(Oled_EventGroupHandle, 
                                        OLED_WIFI_SUCCEED|OLED_WIFI_Fail|OLED_WIFI_APP_CONNECT|OLED_TIME_SYNCHRONIZATION, 
                                        pdTRUE,                     //清理事件 防止重复刷新 
                                        pdFALSE,                    //或语句
                                        portMAX_DELAY);

        if(OLED_WIFI_SUCCEED == (Event_flag&OLED_WIFI_SUCCEED))
        {
            show_str = (u8*)"WIFI SUCCEED";
            OLED_Clear_row_column(2,0,127);
            OLED_Clear_row_column(3,0,127);
            OLED_ShowString(0,2,show_str,16);
            
        }
        else if (OLED_WIFI_Fail == (Event_flag&OLED_WIFI_Fail))
        {
            show_str = (u8*)"WIFI fail--RST";
            // OLED_Clear_row_column(2,0,127);
            // OLED_Clear_row_column(3,0,127);;
            OLED_ShowString(0,2,show_str,16);
        }
        else if (OLED_WIFI_APP_CONNECT == (Event_flag&OLED_WIFI_APP_CONNECT))
        {
            show_str = (u8*)"WIFI APP Connect";
            // OLED_Clear_row_column(2,0,127);
            // OLED_Clear_row_column(3,0,127);
            OLED_ShowString(0,2,show_str,16);
        }

        else if (OLED_TIME_SYNCHRONIZATION == (Event_flag&OLED_TIME_SYNCHRONIZATION))
        {
            xQueueReceive(Time_synchronization_Queue_Handle,&show_Time[0],0);
            //ESP_LOGI("OLED_task", "%s\n",show_Time);
            // OLED_Clear_row_column(2,0,127);
            // OLED_Clear_row_column(3,0,127);
            OLED_ShowString(0,4,&show_Time[11],16);
        }
        
        show_num++;
       // ESP_LOGI("OLED_task","OLED_Task show numb %d" ,show_num);
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
    
}
